$(function () {
    $('#login').click(function () {
        const username = $('#username').val().trim()
        const password = $('#password').val().trim()
        console.log(username, password);
        if (!username || !password) {
            layer.alert('请填写帐号和密码');
            return
        }
        $.ajax({
            url: '/admin/user/login',
            type: 'post',
            data: {
                username,
                password
            },
            success(res) {
                console.log(res);
                if (res.code == 200) {
                    localStorage.setItem('token', res.token)
                    location.href = 'index.html'
                } else {
                    layer.alert('账号密码错误，请重新填写');
                }
            }
        })
    })
})